import { toast } from "react-toastify";

const success = (
  content: React.ReactNode,
  time?: number,
  callback?: () => void
) => {
  toast.success(content, {
    autoClose: time ? time * 1000 : 2000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    draggable: true,
    progress: undefined,
    onClose: callback,
    position: "top-center"
  });
};

const error = (
  content: React.ReactNode,
  time?: number,
  callback?: () => void
) => {
  toast.error(content, {
    autoClose: time ? time * 1000 : 3000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    draggable: true,
    progress: undefined,
    onClose: callback,
    position: "top-center"
  });
};

const warning = (
  content: React.ReactNode,
  time?: number,
  callback?: () => void
) => {
  toast.warning(content, {
    autoClose: time ? time * 1000 : 3000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    draggable: true,
    progress: undefined,
    onClose: callback,
    position: "top-center"
  });
};

const info = (
  content: React.ReactNode,
  time?: number,
  callback?: () => void
) => {
  toast.info(content, {
    autoClose: time ? time * 1000 : 2000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    draggable: true,
    progress: undefined,
    onClose: callback,
    position: "top-center"
  });
};

const destroy = () => toast.dismiss();

export default {
  success,
  error,
  warning,
  info,
  destroy
};
